package br.com.searchpeople.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class SearchPeopleBDOpenHelper extends SQLiteOpenHelper {

	private static final String DATABASE_NAME = "searchpeople_bd";
	private static final int DATABASE_VERSION = 1;
	private static final String POST_TABLE_CREATE = "CREATE TABLE posts (post_id INTEGER PRIMARY KEY AUTOINCREMENT, "+
															 			"name TEXT, " +
															 			"description TEXT, " +
															 			"country TEXT, " +
															 			"state TEXT, "+
															 			"city TEXT, " +
															 			"phone TEXT, " +
															 			"email TEXT, " +
															 			"image BLOB, " +
															 			"latitude DOUBLE," +
															 			"longitude DOUBLE," +
															 			"id_user INTEGER, " +
															 			"date TEXT, " +
															 			"FOREIGN KEY(id_user) REFERENCES accounts(account_id));";
	
	private static final String ACCOUNT_TABLE_CREATE = "CREATE TABLE accounts (account_id INTEGER PRIMARY KEY AUTOINCREMENT, "+
			 																	"email TEXT, " +
			 																	"password TEXT, " +
			 																	"confirm_password TEXT, " +
			 																	"nickname TEXT, "+
			 																	"authtoken TEXT);";

	public SearchPeopleBDOpenHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(POST_TABLE_CREATE);
		db.execSQL(ACCOUNT_TABLE_CREATE);

	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("DROP TABLE IF EXISTS posts");
		db.execSQL("DROP TABLE IF EXISTS accounts");
		onCreate(db);
	}

}
